package com.ruoyi.personnel.service.impl;

import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.personnel.mapper.ELoginInformationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.personnel.mapper.EPersonnelMapper;
import com.ruoyi.personnel.domain.EPersonnel;
import com.ruoyi.personnel.service.IEPersonnelService;

/**
 * 会员管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-21
 */
@Service
public class EPersonnelServiceImpl extends ServiceImpl<EPersonnelMapper, EPersonnel> implements IEPersonnelService
{
    @Autowired
    private EPersonnelMapper ePersonnelMapper;

    /**
     * 查询快递员管理
     *
     * @param id 会员管理主键
     * @return 会员管理
     */
    @Override
    public EPersonnel selectEPersonnelById(Long id)
    {
        return ePersonnelMapper.selectEPersonnelById(id);
    }

    /**
     * 查询快递员管理列表
     *
     * @param ePersonnel 会员管理
     * @return 会员管理
     */
    @Override
    public List<EPersonnel> selectCourierList(EPersonnel ePersonnel)
    {
        return ePersonnelMapper.selectCourierList(ePersonnel);
    }

    /**
     * 查询普通会员管理列表
     *
     * @param ePersonnel 会员管理
     * @return 会员管理
     */
    @Override
    public List<EPersonnel> selectMemberList(EPersonnel ePersonnel)
    {
        return ePersonnelMapper.selectMemberList(ePersonnel);
    }

    /**
     * 新增会员管理
     *
     * @param ePersonnel 会员管理
     * @return 结果
     */
    @Override
    public int insertEPersonnel(EPersonnel ePersonnel)
    {
        String ip=null;
        try {
            InetAddress address = InetAddress.getByName("localhost");
            ip = address.getHostAddress();
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        ePersonnel.setRegisteredIp(ip);
        ePersonnel.setMemberType(Long.valueOf(0));
        ePersonnel.setAvatar("https://spyx-demotest01.oss-cn-beijing.aliyuncs.com/%E5%A4%B4%E5%83%8F/%E5%A4%B4%E5%83%8F.png");
        ePersonnel.setCreateTime(new Date());
        ePersonnel.setMemberBalance(BigDecimal.valueOf(0));
        ePersonnel.setRegistrationType(Long.valueOf(1));
        ePersonnel.setRealNameAuthenticationStatus(Long.valueOf(0));
        ePersonnel.setStatus(Long.valueOf(0));

        int count = ePersonnelMapper.insertEPersonnel(ePersonnel);
        if(count==1){

        }
        return ePersonnelMapper.insertEPersonnel(ePersonnel);
    }

    /**
     * 修改会员管理
     *
     * @param ePersonnel 会员管理
     * @return 结果
     */
    @Override
    public int updateEPersonnel(EPersonnel ePersonnel)
    {
        return ePersonnelMapper.updateEPersonnel(ePersonnel);
    }

    /**
     * 批量删除会员管理
     *
     * @param ids 需要删除的会员管理主键
     * @return 结果
     */
    @Override
    public int deleteEPersonnelByIds(Long[] ids)
    {
        return ePersonnelMapper.deleteEPersonnelByIds(ids);
    }

    /**
     * 删除会员管理信息
     *
     * @param id 会员管理主键
     * @return 结果
     */
    @Override
    public int deleteEPersonnelById(Long id)
    {
        return ePersonnelMapper.deleteEPersonnelById(id);
    }

    /*
    * 重置登录密码
    * */
    @Override
    public int resetLoginPassword(Long lid) {
        if(lid==0){
            return 100;
        }
        return ePersonnelMapper.resetLoginPassword(lid);
    }

    /*
    * 置空支付密码
    * */
    @Override
    public int resetPaymentPassword(Long lid) {
        if(lid==0){
            return 100;
        }
        return ePersonnelMapper.resetPaymentPassword(lid);
    }

    /*
    * 改变当前的状态
    * */
    @Override
    public int updateStatus(EPersonnel ePersonnel) {
        if(ePersonnel.getStatus()==0){
            ePersonnel.setStatus(Long.valueOf(1));
        }else{
            ePersonnel.setStatus(Long.valueOf(0));
        }
        return ePersonnelMapper.updateEPersonnel(ePersonnel);
    }

    /*
    * 添加并获取人员信息
    * */
    @Override
    public EPersonnel insertAndGetResult(EPersonnel ePersonnel) {
        String ip=null;
        try {
            InetAddress address = InetAddress.getByName("localhost");
            ip = address.getHostAddress();
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        ePersonnel.setRegisteredIp(ip);
        ePersonnel.setMemberType(Long.valueOf(0));
        ePersonnel.setAvatar("https://spyx-demotest01.oss-cn-beijing.aliyuncs.com/%E5%A4%B4%E5%83%8F/%E5%A4%B4%E5%83%8F.png");
        ePersonnel.setCreateTime(new Date());
        ePersonnel.setMemberBalance(BigDecimal.valueOf(0));
        ePersonnel.setRegistrationType(Long.valueOf(1));
        ePersonnel.setRealNameAuthenticationStatus(Long.valueOf(0));
        ePersonnel.setStatus(Long.valueOf(0));

        int count = ePersonnelMapper.insertEPersonnel(ePersonnel);
        if(count==1){
            return ePersonnelMapper.selectEPersonnelById(ePersonnel.getId());
        }else {
            throw new RuntimeException("插入操作失败");
        }
    }
}
